package com.bnz.search.controller;

import com.bnz.search.entity.ItemVo;
import com.bnz.search.service.SearchItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;
import java.util.Map;

@Controller
public class SearchController {
    @Autowired
    private SearchItemService searchItemService;
    // 默认的欢迎页面
    @GetMapping({"/","/search.html"})
    // ItemVo封装了各种查询
    public String search(Model model, ItemVo vo) throws IOException {
        // 根据传入的参数vo得到查询结果
        Map<String,Object> resultMap = searchItemService.search(vo);
        // 将得到的结果放到model中
        model.addAttribute("resultMap",resultMap);
        // 得到关键字回传的数据，以便能够在搜索后字段还存在
        model.addAttribute("vo",vo);
        return "search";
    }

}
